﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace ZoambieGaem {
    class Controls {

        public void update(Master m) {

            //Mouse handling
            MouseState mouse = Mouse.GetState();
            int x = mouse.X;
            int y = mouse.Y;
            Vector2 vector = new Vector2(x, y);
            m.mouse = vector;

            //Player angle
            Vector2 mouseLoc = new Vector2(x, y);
            Vector2 direction = (m.player.screenPosition) - vector;
            m.player.angle = (float)(Math.Atan2(direction.Y, direction.X)) + (float)Math.PI;

            if (mouse.LeftButton == ButtonState.Pressed) //ammutaan
                if (m.wpn.reloadCounter >= m.wpn.reloadTime && m.wpn.fireRateCounter >= m.wpn.fireRate)
                    m.wpn.shoot(m);

           

            //Keyboard handling
            KeyboardState keybState = Keyboard.GetState();


            //Jos pelaaja ei ota damagea
            if (!m.player.gettingDamage) {
                
                if (keybState.IsKeyDown(Keys.A)) {
                    m.player.worldPosition = new Vector2(m.player.worldPosition.X - 2, m.player.worldPosition.Y);
                }
                if (keybState.IsKeyDown(Keys.S)) {
                    m.player.worldPosition = new Vector2(m.player.worldPosition.X, m.player.worldPosition.Y + 2);
                }
                if (keybState.IsKeyDown(Keys.D)) {
                    m.player.worldPosition = new Vector2(m.player.worldPosition.X + 2, m.player.worldPosition.Y);
                }
                if (keybState.IsKeyDown(Keys.W)) {
                    m.player.worldPosition = new Vector2(m.player.worldPosition.X, m.player.worldPosition.Y - 2);
                }
            }
            if (keybState.IsKeyDown(Keys.Q)) {
                if (m.drawShadows)
                    m.drawShadows = false;
                else
                    m.drawShadows = true;
            }
            if (keybState.IsKeyDown(Keys.E)) {
                if (m.drawAStar)
                    m.drawAStar = false;
                else
                    m.drawAStar = true;
            }
            
        }
    }
}
